﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //smethod_1("http://www.diadora.com/women/", Encoding.UTF8,"");


         var s=   GetUrltoHtml("http://www.diadora.com/women/","utf-8");
        }


        public static string smethod_1(string string_0, Encoding encoding_0, string string_1, string string_2 = null, System.Net.CookieContainer cookieContainer_0 = null)
        {
            string result = "";
            System.Net.HttpWebRequest httpWebRequest = null;
            System.Net.HttpWebResponse httpWebResponse = null;
            try
            {
                httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(string_0);
                if (string.IsNullOrEmpty(string_2))
                {
                    if (cookieContainer_0 == null)
                    {
                        httpWebRequest.CookieContainer = new System.Net.CookieContainer();
                    }
                    else
                    {
                        httpWebRequest.CookieContainer = cookieContainer_0;
                    }
                }
                else
                {
                    httpWebRequest.Headers.Set("cookie", string_2);
                }
                httpWebRequest.Timeout = 30000;
                httpWebRequest.ReadWriteTimeout = 30000;
                httpWebRequest.Method = "GET";
                httpWebRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
                httpWebRequest.Headers.Add("Accept-Language", "zh-CN");
                if (!string.IsNullOrEmpty(string_1))
                {
                    httpWebRequest.UserAgent = string_1;
                }
                httpWebRequest.Accept = "text/html, text/css";
                //GClass0.smethod_7(httpWebRequest, string_0);
                httpWebResponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse();
                if (!(httpWebResponse.ContentEncoding.ToLower() == "gzip"))
                {
                    if (!(httpWebResponse.ContentEncoding.ToLower() == "deflate"))
                    {
                        using (Stream responseStream = httpWebResponse.GetResponseStream())
                        {
                            using (StreamReader streamReader = new StreamReader(responseStream, encoding_0))
                            {
                                result = streamReader.ReadToEnd();
                            }
                            goto IL_1F1;
                        }
                    }
                    using (Stream responseStream = httpWebResponse.GetResponseStream())
                    {
                        using (System.IO.Compression.DeflateStream deflateStream = new System.IO.Compression.DeflateStream(responseStream, System.IO.Compression.CompressionMode.Decompress))
                        {
                            using (StreamReader streamReader = new StreamReader(deflateStream, encoding_0))
                            {
                                result = streamReader.ReadToEnd();
                            }
                        }
                        goto IL_1F1;
                    }
                }
                using (Stream responseStream = httpWebResponse.GetResponseStream())
                {
                    using (System.IO.Compression.GZipStream gZipStream = new System.IO.Compression.GZipStream(responseStream, System.IO.Compression.CompressionMode.Decompress))
                    {
                        using (StreamReader streamReader = new StreamReader(gZipStream, encoding_0))
                        {
                            result = streamReader.ReadToEnd();
                        }
                    }
                }
                IL_1F1:;
            }
            catch (Exception ex)
            {
                result = ex.Message.ToString();
            }
            if (httpWebResponse != null)
            {
                httpWebResponse.Close();
            }
            if (httpWebRequest != null)
            {
                httpWebRequest.Abort();
            }
            return result;
        }



        public static string GetUrltoHtml(string Url, string type)

        {

            try

            {

                System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url);

                // Get the response instance.

                System.Net.WebResponse wResp = wReq.GetResponse();

                System.IO.Stream respStream = wResp.GetResponseStream();

                // Dim reader As StreamReader = New StreamReader(respStream)

                using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding(type)))
                {
                    return reader.ReadToEnd();
                }

            }

            catch (System.Exception ex)

            {

                //errorMsg = ex.Message;

            }

            return "";

        }
    }
}
